#pragma once

#include "NFServerComm/NFServerCommon/NFIDescStore.h"
#include "NFServerComm/NFServerCommon/NFIDescTemplate.h"
#include "NFLogicCommon/NFDescStoreMacrosDefine.h"
#include "NFLogicCommon/NFDescStoreTypeDefines.h"
#include "E_Bag.nanopb.h"
#ifndef MAX_BAG_BAG_NUM
#define MAX_BAG_BAG_NUM 114
#endif

struct BagTypeTimes
{
	BagTypeTimes()
	{
		if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode()) {
			CreateInit();
		}
		else {
			ResumeInit();
		}
	}
	int CreateInit()
	{
		type=0;
		times=0;
		return 0;
	}
	int ResumeInit()
	{
		return 0;
	}
	int64_t type;
	int64_t times;
	bool operator==(const BagTypeTimes& data) const
	{
		 return type== data.type && times== data.times;
	}
	std::string ToString() const
	{
		std::stringstream ios;
		ios << type;
		ios << ",";
		ios << times;
		return ios.str();
	}
};

namespace std
{
	template<>
	struct hash<BagTypeTimes>
	{
		size_t operator()(const BagTypeTimes& data) const
		{
			return NFHash::hash_combine(data.type,data.times);
		}
	};
}


class BagDesc : public NFI_DESC_TEMPLATE_MACRO(BagDesc, E_Bag, EOT_CONST_BAG_BAG_DESC_ID, MAX_BAG_BAG_NUM)
public:
	BagDesc();
	virtual ~BagDesc();
	int CreateInit();
	int ResumeInit();
public:
	int Load(NFResDb *pDB) override;
	int LoadDB(NFResDb *pDB) override;
	int CheckWhenAllDataLoaded() override;
	const E_Bag* GetDescByTypeTimes(int64_t type, int64_t times);
private:
	NFShmHashMap<BagTypeTimes, uint64_t, MAX_BAG_BAG_NUM> m_typeTimesComIndexMap;
};
